package com.zyit.web;

import com.zyit.DataObject.T_user;
import com.zyit.service.AdminService;
import com.zyit.service.Impl.AdminServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
@WebServlet("/client/register")
public class AddUserServlet extends HttpServlet {
    private AdminService adminService = new AdminServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("执行了");
        T_user tUser = new T_user();
        tUser.setAccount(req.getParameter("account"));
        tUser.setNick_name(req.getParameter("nickName"));
        tUser.setPassword(req.getParameter("password"));
        tUser.setGender(Integer.valueOf(req.getParameter("gender")));
        tUser.setEmail(req.getParameter("email"));
        tUser.setPhone(req.getParameter("phone"));
        tUser.setId_card_no(req.getParameter("idCardNo"));
        System.out.println(tUser);
        adminService.addUser(tUser);

            if (tUser != null ) {

                resp.getWriter().write("{\"status\": 1, \"message\": \"注册成功\"}");
            } else {
                // 登录失败，返回错误的JSON响应
                resp.getWriter().write("{\"status\": 0, \"message\": \"注册失败\"}");

        }
    }
}
